﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Teigha.Core
{
	public class OdGiPolyline : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdGiPolyline(IntPtr cPtr, bool cMemoryOwn) : base(GlobalsPINVOKE.OdGiPolyline_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdGiPolyline obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdGiPolyline()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							GlobalsPINVOKE.delete_OdGiPolyline(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdGiPolyline cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGiPolyline_cast(OdRxObject.getCPtr(pObj));
			OdGiPolyline result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGiPolyline)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGiPolyline)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGiPolyline)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdGiPolyline_desc(), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdGiPolyline_isA(this.swigCPtr), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdGiPolyline_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdGiPolyline createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGiPolyline_createObject();
			OdGiPolyline result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGiPolyline)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGiPolyline)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGiPolyline)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual uint numVerts()
		{
			uint result = GlobalsPINVOKE.OdGiPolyline_numVerts(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool isClosed()
		{
			bool result = GlobalsPINVOKE.OdGiPolyline_isClosed(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdGeVector3d normal()
		{
			OdGeVector3d result = new OdGeVector3d(GlobalsPINVOKE.OdGiPolyline_normal(this.swigCPtr), true);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual double thickness()
		{
			double result = GlobalsPINVOKE.OdGiPolyline_thickness(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual double getConstantWidth()
		{
			double result = GlobalsPINVOKE.OdGiPolyline_getConstantWidth(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool hasWidth()
		{
			bool result = GlobalsPINVOKE.OdGiPolyline_hasWidth(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool hasPlinegen()
		{
			bool result = GlobalsPINVOKE.OdGiPolyline_hasPlinegen(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual double elevation()
		{
			double result = GlobalsPINVOKE.OdGiPolyline_elevation(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdGiPolyline.SegType segType(uint index)
		{
			OdGiPolyline.SegType result = (OdGiPolyline.SegType)GlobalsPINVOKE.OdGiPolyline_segType(this.swigCPtr, index);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void getLineSegAt(uint index, OdGeLineSeg2d ln)
		{
			GlobalsPINVOKE.OdGiPolyline_getLineSegAt__SWIG_0(this.swigCPtr, index, OdGeLineSeg2d.getCPtr(ln));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void getLineSegAt(uint index, OdGeLineSeg3d ln)
		{
			GlobalsPINVOKE.OdGiPolyline_getLineSegAt__SWIG_1(this.swigCPtr, index, OdGeLineSeg3d.getCPtr(ln));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void getArcSegAt(uint index, OdGeCircArc2d arc)
		{
			GlobalsPINVOKE.OdGiPolyline_getArcSegAt__SWIG_0(this.swigCPtr, index, OdGeCircArc2d.getCPtr(arc));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void getArcSegAt(uint index, OdGeCircArc3d arc)
		{
			GlobalsPINVOKE.OdGiPolyline_getArcSegAt__SWIG_1(this.swigCPtr, index, OdGeCircArc3d.getCPtr(arc));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void getPointAt(uint index, OdGePoint2d pt)
		{
			GlobalsPINVOKE.OdGiPolyline_getPointAt(this.swigCPtr, index, OdGePoint2d.getCPtr(pt));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual double getBulgeAt(uint index)
		{
			double result = GlobalsPINVOKE.OdGiPolyline_getBulgeAt(this.swigCPtr, index);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void getWidthsAt(uint index, out double startWidth, out double endWidth)
		{
			GlobalsPINVOKE.OdGiPolyline_getWidthsAt(this.swigCPtr, index, out startWidth, out endWidth);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdRxObject getDbPolyline()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdGiPolyline_getDbPolyline(this.swigCPtr);
			OdRxObject result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		public enum SegType
		{
			kLine,
			kArc,
			kCoincident,
			kPoint,
			kEmpty
		}
	}
}
